﻿using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;
using System.Text;
using System.Web.Services;

public partial class admin_edit_addprop : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    { Session["p_id"] = Request.QueryString["id"].ToString();
        Label67.Visible = false;
        Label67.Text = Session["p_id"].ToString();
        if (Page.IsPostBack == true)
        {
        }
        else
        {

            SqlConnection conn = null;
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
            conn.Open();

            SqlCommand cmd = new SqlCommand("select * from  properties where p_id='" + Request.QueryString["id"] + "'", conn);
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {

               //s DropDownList31.Items.FindByValue(dr["frontend"].ToString()).Selected = true;

                //DropDownList7.Items.FindByValue(dr["agent_name"].ToString()).Selected = true;
             
                TextBox4.Text = dr["cust_type"].ToString();
                txtfname1.Text = dr["fname"].ToString();
                txtlname1.Text = dr["lname"].ToString();

                TextBox22.Text = dr["email_add"].ToString();

                TextBox21.Text = dr["phone_no"].ToString();




                TextBox3.Text = dr["house_no"].ToString();
                TextBox30.Text = dr["city"].ToString();
                TextBox31.Text = dr["street"].ToString();

                TextBox56.Text = dr["block"].ToString();
                TextBox55.Text = dr["sub"].ToString();
                TextBox43.Text = dr["street_no"].ToString();
                TextBox44.Text = dr["app_no"].ToString();
                TextBox23.Text = dr["zip_code"].ToString();
                TextBox24.Text = dr["country"].ToString();

                TextBox32.Text = dr["neigh_hood"].ToString();


                TextBox35.Text = dr["p_neighbor"].ToString();
                TextBox28.Text = dr["p_city"].ToString();
                txtBuildPrivilege.Text = dr["p_state"].ToString();

                TextBox29.Text = dr["p_country"].ToString();

                TextBox51.Text = dr["p_zip"].ToString();

                TextBox50.Text = dr["p_bestreet"].ToString();
                TextBox13.Text = dr["p_behno"].ToString();
                TextBox14.Text = dr["p_beano"].ToString();



                TextBox36.Text = dr["roomno"].ToString();
                //ssDropDownList43.Items.FindByValue(dr["b_pri"].ToString()).Selected = true;
               // DropDownList37.Items.FindByValue(dr["prop_cond"].ToString()).Selected = true;

                TextBox9.Text = dr["cust_propcond"].ToString();
                TextBox25.Text = dr["floorno"].ToString();
                TextBox26.Text = dr["total_flr"].ToString();

               // DropDownList42.Items.FindByValue(dr["build_cond"].ToString()).Selected = true;
                TextBox5.Text = dr["cust_b_cond"].ToString();

                TextBox37.Text = dr["n_of_res"].ToString();

              //  DropDownList43.Items.FindByValue(dr["buildprev"].ToString()).Selected = true;
                TextBox7.Text = dr["cust_build"].ToString();

              //  ddlparking.Items.FindByValue(dr["parking"].ToString()).Selected = true;
                txtpark.Text = dr["cust_parking"].ToString();

               // DropDownList10.Items.FindByValue(dr["basement"].ToString()).Selected = true;

                TextBox27.Text = dr["cust_base"].ToString();

               // DropDownList18.Items.FindByValue(dr["furnt"].ToString()).Selected = true;
                txtfurniture.Text = dr["cust_furnt"].ToString();

               // DropDownList11.Items.FindByValue(dr["storage"].ToString()).Selected = true;

                TextBox34.Text = dr["cust_storage"].ToString();
              //  DropDownList19.Items.FindByValue(dr["toilets"].ToString()).Selected = true;
                txttoilets.Text = dr["cust_toilets"].ToString();
              //  DropDownList56.Items.FindByValue(dr["toilets1"].ToString()).Selected = true;
                TextBox2.Text = dr["cust_toilets1"].ToString();

              //  DropDownList12.Items.FindByValue(dr["ac"].ToString()).Selected = true;
                TextBox54.Text = dr["cust_ac"].ToString();
                //DropDownList20.Items.FindByValue(dr["shower"].ToString()).Selected = true;
                TextBox16.Text = dr["cust_shower"].ToString();
                txtBalconies.SelectedValue = dr["balconies"].ToString();
                TextBox6.Text = dr["balconies_size"].ToString();

                //DropDownList56.Items.FindByValue(dr["sign"].ToString()).Selected = true;

                //txtBalconies0.Items.FindByValue(dr["balconies1"].ToString()).Selected = true;
                TextBox48.Text = dr["balconies_size1"].ToString();

                //DropDownList47.Items.FindByValue(dr["sign1"].ToString()).Selected = true;

                //DropDownList48.Items.FindByValue(dr["g_floor"].ToString()).Selected = true;
                TextBox19.Text = dr["cust_floor"].ToString();
                TextBox33.Text = dr["roof"].ToString();
                //DropDownList16.Items.FindByValue(dr["kitchen"].ToString()).Selected = true;
                TextBox20.Text = dr["cust_kitchen"].ToString();
                TextBox49.Text = dr["balconies_no"].ToString();


                //DropDownList36.Items.FindByValue(dr["view1"].ToString()).Selected = true;
                TextBox8.Text = dr["cust_view1"].ToString();
                //DropDownList39.SelectedValue = dr["f_view"].ToString();
                TextBox11.Text = dr["cust_view"].ToString();
                
                //DropDownList25.Items.FindByValue(dr["garden"].ToString()).Selected = true;
                TextBox18.Text = dr["cust_garden"].ToString();
                //DropDownList33.Items.FindByValue(dr["evacuation_date"].ToString()).Selected = true;
                TextBox10.Text = dr["cust_evacuation_date"].ToString();


                //DropDownList34.Items.FindByValue(dr["land"].ToString()).Selected = true;
                TextBox38.Text = dr["cust_land"].ToString();

                //DropDownList35.Items.FindByValue(dr["area"].ToString()).Selected = true;
                TextBox18.Text = dr["cust_area"].ToString();
                TextBox49.Text = dr["bal_no"].ToString();

                TextBox39.Text = dr["main"].ToString();

               // DropDownList24.Items.FindByValue(dr["build_permit"].ToString()).Selected = true;
                TextBox45.Text = dr["cust_build_permit"].ToString();
                //DropDownList32.Items.FindByValue(dr["boiler"].ToString()).Selected = true; 
                TextBox46.Text = dr["cust_boiler"].ToString();
               // DropDownList44.Items.FindByValue(dr["safe_room"].ToString()).Selected = true;
                TextBox53.Text = dr["custs_room"].ToString();
                //DropDownList50.Items.FindByValue(dr["elevator"].ToString()).Selected = true;

                TextBox47.Text = dr["cust_elevator"].ToString();





                txtProperty.Text = dr["permises"].ToString();
                TextBox41.Text = dr["tax"].ToString();
                TextBox40.Text = dr["propertysize"].ToString();
                //DropDownList41.Items.FindByValue(dr["propertysizesign"].ToString()).Selected = true;
                txtPrice.Text = dr["price"].ToString();
                //DropDownList49.Items.FindByValue(dr["sign4"].ToString()).Selected = true;
                txtOldPrice.Text = dr["oldprice"].ToString();

                //DropDownList51.Items.FindByValue(dr["sign2"].ToString()).Selected = true;

                TextBox52.Text = dr["price_red"].ToString();
            }

        }
    }
    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }
    protected void Save_Click(object sender, System.EventArgs e)
    {


        SqlConnection conn = null;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();
        string filename = FileUpload1.PostedFile.FileName.ToString();

        SqlCommand cmd = new SqlCommand("update properties set frontend=@frontend,type=@type,agent_name=@agent_name,p_type=@p_type,cust_type=@cust_type,fname=@fname,lname=@lname,email_add=@email_add,phone_no=@phone_no,house_no=@house_no,city=@city,street=@street,block=@block ,sub=@sub,street_no=@street_no,app_no=@app_no,zip_code=@zip_code,country=@country,neigh_hood=@neigh_hood,p_neighbor=@p_neighbor,p_city=@p_city,p_state=@p_state,p_country=@p_country,p_zip=@p_zip,p_bestreet=@p_bestreet,p_behno=@p_behno,p_beano=@p_beano,roomno=@roomno,b_pri=@b_pri,prop_cond=@prop_cond,cust_propcond=@cust_propcond,floorno=@floorno,total_flr=@total_flr,build_cond=@build_cond,cust_b_cond=@cust_b_cond,n_of_res=@n_of_res,buildprev=@buildprev,cust_build=@cust_build,parking=@parking,cust_parking=@cust_parking,basement=@basement ,cust_base=@cust_base,furnt=@furnt,cust_furnt=@cust_furnt,storage=@storage,cust_storage=@cust_storage,toilets=@toilets,cust_toilets=@cust_toilets,toilets1=@toilets1,cust_toilets1=@cust_toilets1,ac=@ac,cust_ac=@cust_ac,shower=@shower,cust_shower=@cust_shower,balconies=@balconies,balconies_size=@balconies_size,sign=@sign,balconies1=@balconies1,balconies_size1=@balconies_size1 ,sign1=@sign1,g_floor=@g_floor,cust_floor=@cust_floor,roof=@roof,kitchen=@kitchen,cust_kitchen=@cust_kitchen ,balconies_no=@balconies_no,view1=@view1,cust_view1=@cust_view1,f_view=@f_view,cust_view=@cust_view,garden=@garden,cust_garden=@cust_garden,evacuation_date=@evacuation_date,cust_evacuation_date=@cust_evacuation_date,land=@land,cust_land=@cust_land,area=@area ,cust_area=@cust_area,bal_no=@bal_no,main=@main,build_permit=@build_permit ,cust_build_permit=@cust_build_permit,boiler=@boiler,cust_boiler=@cust_boiler,safe_room=@safe_room,custs_room=@custs_room,elevator=@elevator,cust_elevator=@cust_elevator,permises=@permises,tax=@tax,propertysize=@propertysize,propertysizesign=@propertysizesign,price=@price,sign4=@sign4,oldprice=@oldprice,sign2=@sign2 ,price_red=@price_red,adding_date=@adding_date,adding_by=@adding_by where p_id='" + Request.QueryString["id"].ToString() + "'", conn);


       

        cmd.Parameters.AddWithValue("@frontend", DropDownList31.SelectedValue);
        cmd.Parameters.AddWithValue("@type", "For Sale");
       
        cmd.Parameters.AddWithValue("@agent_name", DropDownList7.SelectedValue);
        cmd.Parameters.AddWithValue("@p_type", d6.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_type", TextBox4.Text);
        cmd.Parameters.AddWithValue("@fname", txtfname1.Text);
        cmd.Parameters.AddWithValue("@lname", txtlname1.Text);

        cmd.Parameters.AddWithValue("@email_add", TextBox22.Text);

        cmd.Parameters.AddWithValue("@phone_no", TextBox21.Text);




        cmd.Parameters.AddWithValue("@house_no", TextBox3.Text);
        cmd.Parameters.AddWithValue("@city", TextBox30.Text);
        cmd.Parameters.AddWithValue("@street", TextBox31.Text);

        cmd.Parameters.AddWithValue("@block", TextBox56.Text);
        cmd.Parameters.AddWithValue("@sub", TextBox55.Text);
        cmd.Parameters.AddWithValue("@street_no", TextBox43.Text);
        cmd.Parameters.AddWithValue("@app_no", TextBox44.Text);
        cmd.Parameters.AddWithValue("@zip_code", TextBox23.Text);
        cmd.Parameters.AddWithValue("@country", TextBox24.Text);

        cmd.Parameters.AddWithValue("@neigh_hood", TextBox32.Text);


        cmd.Parameters.AddWithValue("@p_neighbor", TextBox35.Text);
        cmd.Parameters.AddWithValue("@p_city", TextBox28.Text);
        cmd.Parameters.AddWithValue("@p_state", txtBuildPrivilege.Text);

        cmd.Parameters.AddWithValue("@p_country", TextBox29.Text);

        cmd.Parameters.AddWithValue("@p_zip", TextBox51.Text);

        cmd.Parameters.AddWithValue("@p_bestreet", TextBox50.Text);
        cmd.Parameters.AddWithValue("@p_behno", TextBox13.Text);
        cmd.Parameters.AddWithValue("@p_beano", TextBox14.Text);



        cmd.Parameters.AddWithValue("@roomno", TextBox36.Text);
        cmd.Parameters.AddWithValue("@b_pri", DropDownList43.SelectedValue);
        cmd.Parameters.AddWithValue("@prop_cond", DropDownList37.SelectedValue);

        cmd.Parameters.AddWithValue("@cust_propcond", TextBox9.Text);
        cmd.Parameters.AddWithValue("@floorno", TextBox25.Text);
        cmd.Parameters.AddWithValue("@total_flr", TextBox26.Text);

        cmd.Parameters.AddWithValue("@build_cond", DropDownList42.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_b_cond", TextBox5.Text);

        cmd.Parameters.AddWithValue("@n_of_res", TextBox37.Text);

        cmd.Parameters.AddWithValue("@buildprev", DropDownList43.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_build", TextBox7.Text);

        cmd.Parameters.AddWithValue("@parking", ddlparking.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_parking", txtpark.Text);

        cmd.Parameters.AddWithValue("@basement", DropDownList10.SelectedValue);

        cmd.Parameters.AddWithValue("@cust_base", TextBox27.Text);

        cmd.Parameters.AddWithValue("@furnt", DropDownList18.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_furnt", txtfurniture.Text);

        cmd.Parameters.AddWithValue("@storage", DropDownList11.SelectedValue);

        cmd.Parameters.AddWithValue("@cust_storage", TextBox34.Text);
        cmd.Parameters.AddWithValue("@toilets", DropDownList19.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_toilets", txttoilets.Text);
        cmd.Parameters.AddWithValue("@toilets1", DropDownList56.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_toilets1", TextBox2.Text);


        cmd.Parameters.AddWithValue("@ac", DropDownList12.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_ac", TextBox54.Text);
        cmd.Parameters.AddWithValue("@shower", DropDownList20.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_shower", TextBox16.Text);
        cmd.Parameters.AddWithValue("@balconies", txtBalconies.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies_size", TextBox6.Text);

        cmd.Parameters.AddWithValue("@sign", DropDownList56.SelectedValue);

        cmd.Parameters.AddWithValue("@balconies1", txtBalconies0.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies_size1", TextBox48.Text);

        cmd.Parameters.AddWithValue("@sign1", DropDownList47.SelectedValue);

        cmd.Parameters.AddWithValue("@g_floor", DropDownList48.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_floor", TextBox19.Text);
        cmd.Parameters.AddWithValue("@roof", TextBox33.Text);
        cmd.Parameters.AddWithValue("@kitchen", DropDownList16.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_kitchen", TextBox20.Text);
        cmd.Parameters.AddWithValue("@balconies_no", TextBox49.Text);


        cmd.Parameters.AddWithValue("@view1", DropDownList36.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_view1", TextBox8.Text);
        cmd.Parameters.AddWithValue("@f_view", DropDownList39.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_view", TextBox11.Text);

        cmd.Parameters.AddWithValue("@garden", DropDownList25.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_garden", TextBox18.Text);
        cmd.Parameters.AddWithValue("@evacuation_date", DropDownList33.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_evacuation_date", TextBox10.Text);


        cmd.Parameters.AddWithValue("@land", DropDownList34.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_land", TextBox38.Text);


        cmd.Parameters.AddWithValue("@area", DropDownList35.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_area", TextBox18.Text);
        cmd.Parameters.AddWithValue("@bal_no", TextBox49.Text);

        cmd.Parameters.AddWithValue("@main", TextBox39.Text);

        cmd.Parameters.AddWithValue("@build_permit", DropDownList24.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_build_permit", TextBox45.Text);
        cmd.Parameters.AddWithValue("@boiler", DropDownList32.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_boiler", TextBox46.Text);
        cmd.Parameters.AddWithValue("@safe_room", DropDownList44.SelectedValue);
        cmd.Parameters.AddWithValue("@custs_room", TextBox53.Text);
        cmd.Parameters.AddWithValue("@elevator", DropDownList50.SelectedValue);

        cmd.Parameters.AddWithValue("@cust_elevator", TextBox47.Text);





        cmd.Parameters.AddWithValue("@permises", txtProperty.Text);
        cmd.Parameters.AddWithValue("@tax", TextBox41.Text);
        cmd.Parameters.AddWithValue("@propertysize", TextBox40.Text);
        cmd.Parameters.AddWithValue("@propertysizesign", DropDownList41.SelectedValue);
        cmd.Parameters.AddWithValue("@price", txtPrice.Text);
        cmd.Parameters.AddWithValue("@sign4", DropDownList49.SelectedValue);
        cmd.Parameters.AddWithValue("@oldprice", txtOldPrice.Text);

        cmd.Parameters.AddWithValue("@sign2", DropDownList51.SelectedValue);

        cmd.Parameters.AddWithValue("@price_red", TextBox52.Text);









      
        cmd.Parameters.AddWithValue("@adding_date", System.DateTime.Now);
        cmd.Parameters.AddWithValue("@adding_by", "admin");


        cmd.ExecuteNonQuery();
      
        
            
        

      



         
      

       

    
        Response.Redirect("property_add_confirmation.aspx");
    }
            

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "action")
        {

            //Label1.Text = "hello";
            int index = Convert.ToSByte(e.CommandArgument);

            GridViewRow row = GridView2.Rows[index];
            SqlDataAdapter adp = new SqlDataAdapter();
            SqlCommand cmd1 = new SqlCommand();
            DataSet ds = new DataSet();


            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

            con.Open();

            SqlCommand objectvalue = new SqlCommand("", con);
            cmd1.Connection = con;

            SqlCommand dmc = new SqlCommand("Delete from properties_rent where p_id='" + row.Cells[0].Text + "'", con);
            dmc.ExecuteNonQuery();

            // SqlCommand dmc = new SqlCommand("select p_id from properties where p_id='" + row.Cells[0].Text + "'", con);

            //dmc.ExecuteNonQuery();
            //  Session["p_id"] = row.Cells[0].Text;

            con.Close();
            // Response.Write(Session["p_id"]);
            // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

            Response.Redirect("report_property_for_rent.aspx");
            // con.Close();


        }



        if (e.CommandName == "view")
        {

            //Label1.Text = "hello";
            int index = Convert.ToSByte(e.CommandArgument);

            GridViewRow row = GridView2.Rows[index];
            SqlDataAdapter adp = new SqlDataAdapter();
            SqlCommand cmd1 = new SqlCommand();
            DataSet ds = new DataSet();


            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

            con.Open();

            SqlCommand objectvalue = new SqlCommand("", con);
            cmd1.Connection = con;



            SqlCommand dmc = new SqlCommand("select t_id from task where t_id='" + row.Cells[1].ToString() + "'", con);

            dmc.ExecuteNonQuery();
            Session["t_id"] = row.Cells[1].Text.ToString();

            con.Close();
            // Response.Write(Session["p_id"]);
            // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

            Response.Redirect("edit-task.aspx");
            // con.Close();


        }

    }

}